<template>
  <div class="goods_list">
    <el-container>
      <el-header>
        <header-item :item="tips"></header-item>
      </el-header>
      <el-main>
        <main-tools-item :toolsType="toolsType" :searchType="searchType" :inputValue="inputValue" @search='search' @add='add'></main-tools-item>
        <main-spare-item @onClick=''></main-spare-item>
        <main-data-list-item :columns="columns" :dataList="dataList" :arrayImgs="arrayImgs" :pager="page" @batchDelete='batchDelete'
          @currentChange='currentChange'>
          <el-table-column label="操作" slot="table_oper" min-width="160px">
            <template slot-scope="scope">
              <el-button size="mini" type="success" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
              <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </main-data-list-item>
      </el-main>
    </el-container>
    <!--新增弹框 -->
    <el-dialog title="新增" :visible.sync="addDialogVisible" width="30%" :before-close="addBeforeClose" close-on-press-escape close-on-click-modal
      class="defaultDialog" :modal="false">
      <el-form ref="addParam" :rules="addAndEditRules" :model="addParam" label-width="30%">
        <template v-for="(item, index) in addAndEditColumns">
          <el-form-item :label="item.label" :key="index" :prop="item.value">
            <el-cascader v-if="item.value =='pid'" v-model="addParam[item.value]" :options="goodsThrTypeOptions" @change="addThrTypeSelect"
              :show-all-levels="true" :props="{}" style="" />
            <el-select v-else-if="item.value =='bid'" v-model="addParam[item.value]" placeholder="请选择">
              <el-option v-for="item in bidOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
            <el-select v-else-if="item.value =='status'" v-model="addParam[item.value]" placeholder="请选择">
              <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
            <el-select v-else-if="item.value =='couponEnable'" v-model="addParam[item.value]" placeholder="请选择">
              <el-option v-for="item in couponEnableOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
            <el-select v-else-if="item.value =='pointEnable'" v-model="addParam[item.value]" placeholder="请选择">
              <el-option v-for="item in pointEnableOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
            <el-select v-else-if="item.value =='invoiceEnable'" v-model="addParam[item.value]" placeholder="请选择">
              <el-option v-for="item in invoiceEnableOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
            <WE v-else-if="item.value =='detail'" ref="we_add" :catchData="addCatchData" :defaultMsg="addParam[item.value]"></WE>
            <!-- <UE  v-else-if="item.value =='detail'"  :defaultMsg="addParam[item.value]" :config=config ref="ue"></UE> -->
            <el-upload v-else-if="item.value =='icon'" class="upload-demo" :action="uploadUrl" :on-remove="addIconHandleRemove" :on-success="addIconHandleSuccess"
              :file-list="addIconFileList" list-type="picture" name="file" :limit="1" :headers="uploadHeaders">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
            <el-upload v-else-if="item.value =='imgs'" class="upload-demo" :action="uploadUrl" :on-remove="addImgsHandleRemove" :on-success="addImgsHandleSuccess"
              :file-list="addImgsFileList" list-type="picture-card" name="file" :headers="uploadHeaders" multiple>
              <i class="el-icon-plus"></i>
            </el-upload>
            <el-input v-else-if="item.value =='profile'" type="textarea" :rows="2" placeholder="请输入内容" v-model="addParam[item.value]">
            </el-input>
            <el-input v-else v-model="addParam[item.value]"></el-input>
          </el-form-item>
        </template>
        <el-form-item>
          <el-button size="mini" type="primary" @click="addSumbit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--编辑弹框 -->
    <el-dialog title="编辑" :visible.sync="editDialogVisible" width="30%" :before-close="editBeforeClose" close-on-press-escape
      close-on-click-modal :modal="false" class="defaultDialog">
      <el-form ref="editParam" :rules="addAndEditRules" :model="editParam" label-width="30%">
        <template v-for="(item, index) in addAndEditColumns">
          <el-form-item :label="item.label" :key="index">
            <el-cascader v-if="item.value =='pid'" v-model="editParam[item.value]" :options="goodsThrTypeOptions" @change="editThrTypeSelect"
              :props="{}" style="" />
            <el-select v-else-if="item.value =='bid'" v-model="editParam[item.value]" placeholder="请选择">
              <el-option v-for="item in bidOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
            <el-select v-else-if="item.value =='status'" v-model="editParam[item.value]" placeholder="请选择">
              <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
            <el-upload v-else-if="item.value =='icon'" class="upload-demo" :action="uploadUrl" :on-remove="editIconHandleRemove" :on-success="editIconHandleSuccess"
              :file-list="editIconFileList" list-type="picture" name="file" :limit="1" :headers="uploadHeaders">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
            <WE v-else-if="item.value =='detail'" ref="we_edit" :catchData="editCatchData" :defaultMsg="editParam[item.value]"></WE>
            <el-upload v-else-if="item.value =='imgs'" class="upload-demo" :action="uploadUrl" :on-remove="editImgsHandleRemove" :on-success="editImgsHandleSuccess"
              :file-list="editImgsFileList" list-type="picture-card" name="file" :headers="uploadHeaders">
              <i class="el-icon-plus"></i>
            </el-upload>
            <el-input v-else-if="item.value =='profile'" type="textarea" :rows="2" placeholder="请输入内容" v-model="editParam[item.value]"></el-input>
            <el-input v-else v-model="editParam[item.value]"></el-input>
          </el-form-item>
        </template>
        <el-form-item>
          <el-button size="mini" type="primary" @click="editSumbit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import {
    get,
    post,
    pat,
    del,
    common,
    getRefresh
  } from "../../../../api/api";
  import headerItem from "./../../Commons/headerItem.vue";
  import mainToolsItem from "./../../Commons/mainToolsItem.vue";
  import mainSpareItem from "./../../Commons/mainSpareItem.vue";
  import mainDataListItem from "./../../Commons/mainDataListItem.vue";
  import config from "../../../../../static/config.js";
  export default {
    components: {
      headerItem,
      mainToolsItem,
      mainSpareItem,
      mainDataListItem,
      UE: () =>
        import ('../ue.vue'),
      WE: () =>
        import ('../Wangeditor.vue')
    },
    data() {
      return {
        tips: "商品信息",
        uploadUrl: window.dict.url + "/goods/upFilePic",
        toolsType: 1,
        searchType: 5,
        inputValue: '请输入商品名称',
        sels: [],
        page: {
          pageNo: 1,
          limit: 10,
          sizes: [10, 50, 100],
          total: 0
        },
        columns: [{
            prop: 'id',
            label: '商品id',
            width: '120',
            align: 'center'
          },
          // {
          //   prop: 'bid',
          //   label: '品牌id',
          //   width: '',
          //   align: 'center',
          // },
          // {
          //   prop: 'pid',
          //   label: '父类id',
          //   width: '',
          //   align: 'center'
          // },
          // {
          //   prop: 'ppid',
          //   label: '父类的父类id',
          //   width: '',
          //   align: 'center'
          // },
          // {
          //   prop: 'topId',
          //   label: '顶级分类id',
          //   width: '',
          //   align: 'center'
          // },
          {
            prop: 'name',
            label: '商品名称',
            width: '300px',
            align: 'center'
          },
          {
            prop: 'icon',
            label: '商品图标',
            width: '80px',
            align: 'center'
          },
          {
            prop: 'goodsListImgs',
            label: '商品轮播图',
            width: '200px',
            align: 'center'
          },
          {
            prop: 'tips',
            label: '提示信息',
            width: '200px',
            align: 'center'
          },
          {
            prop: 'detail',
            label: '详情信息',
            width: '200px',
            align: 'center'
          },
          {
            prop: 'profile',
            label: '简介',
            width: '180px',
            align: 'center'
          },
          {
            prop: 'scanNum',
            label: '浏览量',
            width: '100px',
            align: 'center'
          },
          {
            prop: 'monthSalesNum',
            label: '月销量',
            width: '100px',
            align: 'center'
          },
          {
            prop: 'totalSalesNum',
            label: '总销量',
            width: '100px',
            align: 'center'
          },
          {
            prop: 'commentNum',
            label: '评论数',
            width: '100px',
            align: 'center'
          },
          {
            prop: 'guaranteeInfo',
            label: '保障信息',
            width: '100px',
            align: 'center'
          },
          {
            prop: 'freight',
            label: '运费',
            width: '100px',
            align: 'center'
          },
          {
            prop: 'couponEnable',
            label: '优惠券使用',
            width: '100px',
            align: 'center'
          },
          {
            prop: 'pointEnable',
            label: '积分抵扣',
            width: '100px',
            align: 'center'
          },
          {
            prop: 'invoiceEnable',
            label: '开发票',
            width: '100px',
            align: 'center'
          },
          {
            prop: 'svip1ShareMoney',
            label: 'SVIP1分享链接购买获得收益金额',
            width: '230',
            align: 'center'
          },
          {
            prop: 'svip2ShareMoney',
            label: 'SVIP2分享链接购买获得收益金额',
            width: '230',
            align: 'center'
          },
          {
            prop: 'svip3ShareMoney',
            label: 'SVIP3分享链接购买获得收益金额',
            width: '230',
            align: 'center'
          },
          {
            prop: 'svip4ShareMoney',
            label: 'SVIP4分享链接购买获得收益金额',
            width: '230',
            align: 'center'
          },
          {
            prop: 'maxPoint',
            label: '最大积分抵扣数',
            width: '140px',
            align: 'center'
          },
          {
            prop: 'status',
            label: '状态',
            width: '',
            align: 'center'
          },
          {
            prop: 'createUser',
            label: '创建用户',
            width: '',
            align: 'center'
          },
          {
            prop: 'createTime',
            label: '创建时间',
            width: '',
            align: 'center'
          }
        ],
        dataList: [],
        loading: false,
        param: {
          name: '',
          size: '10',
          current: '1'
        },
        addParam: {
          status: 1,
          couponEnable: 1,
          pointEnable: 1,
          invoiceEnable: 1
        },
        addAndEditColumns: [
          // {
          //   value: 'id',
          //   label: '商品id',
          // },
          {
            value: 'bid',
            label: '品牌',
          },
          {
            value: 'pid',
            label: '分类',
          },
          // {
          //   value: 'ppid',
          //   label: '父类的父类id',
          // },
          // {
          //   value: 'topId',
          //   label: '顶级分类id',
          // },
          {
            value: 'name',
            label: '商品名称',
          },
          {
            value: 'icon',
            label: '商品图标',
          },
          {
            value: 'imgs',
            label: '商品轮播图',
          },
          {
            value: 'tips',
            label: '提示信息',
          },
          {
            value: 'detail',
            label: '详情信息',
          },
          {
            value: 'profile',
            label: '简介',
          },
          {
            value: 'scanNum',
            label: '浏览量',
          },
          {
            value: 'monthSalesNum',
            label: '月销量',
          },
          {
            value: 'totalSalesNum',
            label: '总销量',
          },
          {
            value: 'commentNum',
            label: '评论数',
          },
          {
            value: 'guaranteeInfo',
            label: '保障信息',
          },
          {
            value: 'freight',
            label: '运费',
          },
          {
            value: 'couponEnable',
            label: '优惠券使用',
          },
          {
            value: 'pointEnable',
            label: '积分抵扣',
          },
          {
            value: 'invoiceEnable',
            label: '开发票',
          },
          // {
          //   value: 'svip1Discount',
          //   label: 'SVIP1优惠金额',
          // },
          // {
          //   value: 'svip2Discount',
          //   label: 'SVIP2优惠金额',
          // },
          // {
          //   value: 'svip3Discount',
          //   label: 'SVIP3优惠金额',
          // },
          // {
          //   value: 'svip4Discount',
          //   label: 'SVIP4优惠金额',
          // },
          {
            value: 'svip1ShareMoney',
            label: 'SVIP1分享链接购买获得收益金额',
          },
          {
            value: 'svip2ShareMoney',
            label: 'SVIP2分享链接购买获得收益金额',
          },
          {
            value: 'svip3ShareMoney',
            label: 'SVIP3分享链接购买获得收益金额',
          },
          {
            value: 'svip4ShareMoney',
            label: 'SVIP4分享链接购买获得收益金额',
          },
          {
            value: 'maxPoint',
            label: '最大积分抵扣数',
          },
          {
            value: 'status',
            label: '状态',
          }
        ],
        editParam: {},
        statusOptions: [{
          label: "不可用",
          value: 0
        }, {
          label: "可用",
          value: 1
        }],
        couponEnableOptions: [{
          label: "不能使用",
          value: 0
        }, {
          label: "可以使用",
          value: 1
        }],
        pointEnableOptions: [{
          label: "不支持",
          value: 0
        }, {
          label: "支持",
          value: 1
        }],
        invoiceEnableOptions: [{
          label: "不支持",
          value: 0
        }, {
          label: "支持",
          value: 1
        }],
        bidOptions: [],
        addAndEditRules: {
          bid: [{
            required: true,
            message: '请输入内容',
            trigger: 'blur'
          }],
          pid: [{
            required: true,
            message: '请选择分类',
            trigger: 'blur'
          }],
          name: [{
            required: true,
            message: '请输入内容',
            trigger: 'blur'
          }],
          // icon: [{
          //   required: true,
          //   message: '请选择图片',
          //   trigger: 'blur'
          // }],
          // imgs: [{
          //   required: true,
          //   message: '请选择图片',
          //   trigger: 'blur'
          // }],
        },
        arrayImgs: [],
        goodsSecTypeOptions: [],
        goodsThrTypeOptions: [],
        addDialogVisible: false,
        editDialogVisible: false,
        addIconFileList: [],
        addImgsFileList: [],
        editIconFileList: [],
        editImgsFileList: [],
        uploadHeaders: {
          'token': localStorage.getItem('token')
        },
      };
    },
    methods: {
      //--------查询----------
      search(val) {
        this.param = {}
        this.param.name = "";
        this.param.name = val.name;
        this.getGoodsList();
      },
      //--------新增----------
      addBeforeClose(done) {
        this.addIconFileList = []
        this.addImgsFileList = []
        done()
      },
      add() {
        this.addDialogVisible = true;
        this.addParam = {
          'status': 1,
        }
        setTimeout(() => {
          this.$refs.we_add[0].setContent("");　
        }, 0)
        this.getSecGoodsCategory();
        this.getThrGoodsCategory();
        this.getGoodsBrandList();
      },
      addSumbit() {
        this.$refs['addParam'].validate(valid => {
          if (valid) {
            this.addDialogVisible = false;
            this.addIconFileList = []
            this.addImgsFileList = []
            this.addGoods();
          }
        })
      },
      addSecTypeSelect(val) {},
      addThrTypeSelect(val) {},
      addHandlePreview() {},
      addIconHandleRemove() {
        this.addParam.icon = " "
      },
      addImgsHandleRemove(file, fileList) {
        var midArray = []
        for (var item in fileList) {
          midArray.push(fileList[item].response.data)
        }
        this.addParam.imgs = midArray.join(";")
      },
      addIconHandleSuccess(response, file, fileList) {
        this.addParam.icon = response.data
      },
      addImgsHandleSuccess(response, file, fileList) {
        var midArray = []
        for (var item in fileList) {
          if (fileList[item].response) {
            midArray.push(fileList[item].response.data)
          }
        }
        this.addParam.imgs = midArray.join(";")
      },
      addCatchData(val) {
        this.addParam.detail = val
      },
      //--------编辑----------
      editBeforeClose(done) {
        this.editIconFileList = []
        this.editImgsFileList = []
        done()
      },
      handleEdit(index, row) {
        this.editDialogVisible = true;
        this.editParam = JSON.parse(JSON.stringify(row));
        setTimeout(() => {
          this.$refs.we_edit[0].setContent(row.detail);　
        }, 0)
        if (row.icon && row.icon != " ") {
          this.editIconFileList = [{
            name: row.name,
            url: row.icon
          }]
        }
        this.editImgsFileList = []
        if (row.imgs && row.imgs != " ") {
          for (var item in row.imgs) {
            this.editImgsFileList.push({
              name: row.name,
              url: row.imgs[item]
            })
          }
        }
        this.getSecGoodsCategory();
        this.getThrGoodsCategory();
        this.getGoodsBrandList();
      },
      editSumbit() {
        this.editDialogVisible = false;
        this.editGoods();
      },
      editSecTypeSelect(val) {},
      editThrTypeSelect(val) {},
      editHandlePreview() {},
      editIconHandleRemove(file, fileList) {
        this.editParam.icon = " "
      },
      editImgsHandleRemove(file, fileList) {
        var midArray = []
        for (var item in fileList) {
          if (fileList[item].response != null) {
            midArray.push(fileList[item].response.data)
          } else {
            midArray.push(fileList[item].url)
          }
        }
        this.editParam.imgs = midArray
        // if (this.editParam.imgs.length == 0) {
        //   this.editParam.imgs = " "
        // }
      },
      editIconHandleSuccess(response, file, fileList) {
        this.editParam.icon = response.data
      },
      editImgsHandleSuccess(response, file, fileList) {
        var midArray = []
        for (var item in fileList) {
          if (fileList[item].response != null) {
            midArray.push(fileList[item].response.data)
          } else {
            midArray.push(fileList[item].url)
          }
        }
        this.editParam.imgs = midArray

      },
      editCatchData(val) {
        this.editParam.detail = val
      },
      //--------删除----------
      handleDelete(index, row) {
        this.delConfirm(row.id);
      },
      batchDelete(val) {},
      //-------分页----------
      currentChange(val) {
        this.param.current = "";
        this.param.current = val
        this.getGoodsList();
      },
      //获取list列表
      getGoodsList() {
        return new Promise((resolve, reject) => {
          var param = {};
          for (let key in this.param) {
            if (this.param[key] != null && this.param[key].length != 0) {
              param[key] = this.param[key]
            }
          }
          post("/goods/selectXasGoodsList", param).then(resdata => {
              let self = function () {
                this.$router.push({
                  path: '/home'
                });
              }.bind(this);
              let error = function () {
                alert(resdata.msg)
              }.bind(this);
              let success = function () {
                if (resdata.code == 1) {
                  this.dataList = resdata.data.records;
                  this.page.total = resdata.data.total;
                  for (var item in this.dataList) {
                    if (this.dataList[item].imgs && this.dataList[item].imgs != " ") {
                      this.dataList[item].imgs = this.dataList[item].imgs.split(";");
                    }
                  }
                }
              }.bind(this);
              common(self)(error)(success)(resdata);
              resolve();
            })
            .catch(e => {
              this.$message({
                message: e,
                type: "error"
              });
            });
        });
      },
      getSecGoodsCategory() {
        return new Promise((resolve, reject) => {
          get("/goods/secGoodsCategory").then(resdata => {
            let self = function () {
              this.$router.push({
                path: '/home'
              });
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 1) {
                var list = resdata.data;
                var newList = [];
                const getStr = function (list, newList) {
                  for (var i = 0; i < list.length; i++) {
                    var midList = {};
                    midList.value = list[i].id;
                    midList.label = list[i].name;
                    if (list[i].goodsCategoryList) {
                      midList.children = [];
                      newList[i] = midList;
                      getStr(list[i].goodsCategoryList, newList[i].children)
                    }
                    newList[i] = midList;
                  }
                }
                getStr(list, newList)
                this.goodsSecTypeOptions = newList;
              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      },
      getThrGoodsCategory() {
        return new Promise((resolve, reject) => {
          get("/goods/thrGoodsCategory").then(resdata => {
            let self = function () {
              this.$router.push({
                path: '/home'
              });
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 1) {
                var list = resdata.data;
                var newList = [];
                const getStr = function (list, newList) {
                  for (var i = 0; i < list.length; i++) {
                    var midList = {};
                    midList.value = list[i].id;
                    midList.label = list[i].name;
                    if (list[i].goodsCategoryList) {
                      midList.children = [];
                      newList[i] = midList;
                      getStr(list[i].goodsCategoryList, newList[i].children)
                    }
                    newList[i] = midList;
                  }
                }
                getStr(list, newList)
                this.goodsThrTypeOptions = newList;
              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      },
      getGoodsBrandList() {
        return new Promise((resolve, reject) => {
          post("/goods/selectXasGoodsBrand", {
            'size': 10000,
            'current': 1
          }).then(resdata => {
            let self = function () {
              this.$router.push({
                path: '/home'
              });
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 1) {
                var list = resdata.data.records;
                var newList = [];
                const getStr = function (list, newList) {
                  for (var i = 0; i < list.length; i++) {
                    var midList = {};
                    midList.value = list[i].id;
                    midList.label = list[i].name;
                    newList[i] = midList;
                  }
                }
                getStr(list, newList)
                this.bidOptions = newList;
              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      },
      addGoods() {
        return new Promise((resolve, reject) => {
          var addParam = {};
          for (let key in this.addParam) {
            if (this.addParam[key] != null && this.addParam[key].length != 0) {
              addParam[key] = this.addParam[key]
            }
            if (key == "pid") {
              addParam[key] = this.addParam[key][this.addParam[key].length - 1];
              addParam["ppid"] = this.addParam[key][this.addParam[key].length - 2];
              addParam["topId"] = this.addParam[key][this.addParam[key].length - 3];
            }
          }
          post("/goods/addXasGoodsList", addParam).then(resdata => {
              let self = function () {
                this.$router.push({
                  path: '/home'
                });
              }.bind(this);
              let error = function () {
                alert(resdata.msg)
              }.bind(this);
              let success = function () {
                if (resdata.code == 1) {
                  this.$message({
                    message: '新增成功！',
                    type: 'success',
                    duration: 2000,
                  });
                  this.getGoodsList();
                }
              }.bind(this);
              common(self)(error)(success)(resdata);
              resolve();
            })
            .catch(e => {
              this.$message({
                message: e,
                type: "error"
              });
            });
        });
      },
      editGoods() {
        return new Promise((resolve, reject) => {
          var editParam = {};
          var ppid = "";
          var topId = "";
          for (let key in this.editParam) {
            if (this.editParam[key] != null && this.editParam[key].length != 0) {
              editParam[key] = this.editParam[key]
            }
            if (key == "pid") {
              editParam[key] = this.editParam[key][this.editParam[key].length - 1];
              ppid = this.editParam[key][this.editParam[key].length - 2];
              topId = this.editParam[key][this.editParam[key].length - 3];
            }
            if (key == "icon") {
              editParam[key] = this.editParam[key]
            }
            if (key == "imgs") {
              var midArray = []
              for (var item in this.editParam[key]) {
                midArray.push(this.editParam[key][item])
              }
              editParam.imgs = midArray.join(";")
            }
          }
          editParam["ppid"] = ppid;
          editParam["topId"] = topId;
          post("/goods/updateXasGoodsList", editParam).then(resdata => {
              let self = function () {
                this.$router.push({
                  path: '/home'
                });
              }.bind(this);
              let error = function () {
                alert(resdata.msg)
              }.bind(this);
              let success = function () {
                if (resdata.code == 1) {
                  this.$message({
                    message: '编辑成功！',
                    type: 'success',
                    duration: 2000,
                  });
                  this.getGoodsList();
                }
              }.bind(this);
              common(self)(error)(success)(resdata);
              resolve();
            })
            .catch(e => {
              this.$message({
                message: e,
                type: "error"
              });
            });
        });
      },
      delConfirm(id) {
        this.$confirm('确定删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.delGoods(id);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      delGoods(id) {
        return new Promise((resolve, reject) => {
          post("/goods/delXasGoodsList", {
            'id': id
          }).then(resdata => {
            let self = function () {
              this.$router.push({
                path: '/home'
              });
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 1) {
                this.$message({
                  message: '删除成功！',
                  type: 'success',
                  duration: 2000,
                });
                this.getGoodsList();
              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      }
    },
    async mounted() {
      await this.getGoodsList();
    },
    watch: {}
  };

</script>

<style lang="scss">
  .goods_list {
    background-color: white;
    font-size: 1.8rem;
    width: 100%;
    height: 100%;
    .el-container {
      height: 100%;
      .el-header,
      .el-footer {
        background-color: #F9FAFE;
        color: #333;
        text-align: center;
        line-height: 50px;
        height: 50px !important;
        .header-child {
          height: 50px;
          width: 100%;
          text-align: left;
          padding-left: 20px;
          background-color: #cbe9eb;
          border-bottom: 1px solid black;
          box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5);
        }
      }
      .el-main {
        box-shadow: 0 5px 5px 0px rgba(0, 0, 0, 0.5); // margin: 10px 20px;
        margin: 10px;
        background-color: #fff;
        color: #333;
        text-align: center;
        height: 100%;
      }
    }
    /* 弹框CSS*/
    .defaultDialog {
      z-index: 1200 !important;
      .el-dialog {
        box-shadow: 0px 5px 15px 0 rgba(0, 0, 0, 0.5);
        border-radius: 5px;
        width: 50% !important;
        .el-dialog__header {
          text-align: left;
          .el-dialog__title {
            font-family: "Roboto", sans-serif;
            color: #7d7d7d;
            font-size: 15px;
          }
        }
        .el-dialog__body {
          .el-form {
            padding-left: 40px;
            .el-form-item {
              width: 100%;
              .el-form-item__content {
                text-align: left;
                width: 250px;
                .el-cascader {
                  width: 100%;
                }
                .el-select {
                  width: 100%;
                }
              }
              .el-form-item__label {
                padding: 0 50px 0 0;
                min-width: 80px;
                color: #333;
                font-weight: 400;
                font-size: 13px;
              }
            }
          }
        }
      }
    }
  }

</style>
